//
//  HDPersonalInfoCell.m
//  HDecoration
//
//  Created by 曹群 on 15/8/16.
//  Copyright (c) 2015年 HDecoration. All rights reserved.
//

#import "HDPersonalInfoCell.h"
@interface HDPersonalInfoCell ()
@property(nonatomic,strong)DOImageView *photo;
@property(nonatomic,strong)UILabel *nameLabel;
@property(nonatomic,strong)UILabel *teachLevelLabel;
@property(nonatomic,strong)UILabel *subjectLabel;
@property(nonatomic,strong)UILabel *coachLevelLabel;
@property(nonatomic,strong)GXLevelControl *starLevel;
@end

@implementation HDPersonalInfoCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.photo];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.teachLevelLabel];
        [self.contentView addSubview:self.subjectLabel];
        [self.contentView addSubview:self.coachLevelLabel];
        UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.coachLevelLabel.bottom+12, APPFRAME.size.width, 0.5)];
        line.image = [UIImage imageNamed:@"dot"];
        [self.contentView addSubview:line];
        NSArray *titleArr = @[@"学车\n抢单数",@"练车\n抢单数",@"好评率",@"排名"];
        for (int i=0; i<4; i++)
        {
            UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(APPFRAME.size.width/4.0*i, line.bottom, APPFRAME.size.width/4.0, 40)];
            titleLabel.textColor = [UIColor hexStringToColor:@"#8b8b8b"];
            titleLabel.font = [UIFont systemFontOfSize:12];
            titleLabel.numberOfLines = 0;
            titleLabel.textAlignment = NSTextAlignmentCenter;
            titleLabel.text = titleArr[i];
            UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(APPFRAME.size.width/4.0*i, titleLabel.bottom, APPFRAME.size.width/4.0, 30)];
            contentLabel.textColor = kDarkGrayColor;
            contentLabel.font = [UIFont systemFontOfSize:13];
            contentLabel.textAlignment = NSTextAlignmentCenter;
            contentLabel.tag = 100+i;
            [self.contentView addSubview:titleLabel];
            [self.contentView addSubview:contentLabel];
        }
        [self.contentView addSubview:self.starLevel];
    }
    return self;
}

- (void)setPersonalInfo:(HDPersonalInfo *)personalInfo
{
    if(personalInfo==nil)
        return;
    
    _personalInfo = [personalInfo copy];
    self.photo.imgURLStr = _personalInfo.photoUrl;
    self.nameLabel.text = _personalInfo.name;
    self.teachLevelLabel.text = [NSString stringWithFormat:@"教学等级：%@",_personalInfo.teachLevel];
    self.subjectLabel.hidden = netEngine.coachInfo.user_type.intValue==2;
    self.subjectLabel.text = [NSString stringWithFormat:@"专长科目：%@",_personalInfo.subject];
    self.coachLevelLabel.text = [NSString stringWithFormat:@"教练等级：%@",_personalInfo.coachLevel];
    NSArray *contentArr = @[_personalInfo.learningOrderCount,_personalInfo.practiceOrderCount,_personalInfo.highOpinionRate,_personalInfo.rank];
    for (int i=0; i<4; i++)
    {
        UILabel *contentLabel = (UILabel *)[self.contentView viewWithTag:100+i];
        contentLabel.text = contentArr[i];
    }
    self.starLevel.levelNum = _personalInfo.starLevel;
}

+(CGFloat)cellHeight:(HDPersonalInfo *)personalInfo
{
    return 170;
}

#pragma mark - getters
- (UIImageView *)photo
{
    if (!_photo) {
        _photo = [[DOImageView alloc] initWithFrame:CGRectMake(10, 15, 50, 50)];
        _photo.layer.cornerRadius = 5;
        _photo.layer.masksToBounds = YES;
        _photo.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _photo;
}

- (UILabel *)nameLabel
{
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photo.right+15, 15, 100, 20)];
        _nameLabel.font = [UIFont systemFontOfSize:15];
        _nameLabel.textColor = kDarkGrayColor;
    }
    return _nameLabel;
}

- (UILabel *)teachLevelLabel
{
    if (!_teachLevelLabel) {
        _teachLevelLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photo.right+15, self.nameLabel.bottom, APPFRAME.size.width-130, 16)];
        _teachLevelLabel.font = [UIFont systemFontOfSize:12];
        _teachLevelLabel.textColor = kLightGrayColor;
    }
    return _teachLevelLabel;
}

- (UILabel *)subjectLabel
{
    if (!_subjectLabel) {
        _subjectLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photo.right+15, self.teachLevelLabel.bottom, APPFRAME.size.width-130, 16)];
        _subjectLabel.font = [UIFont systemFontOfSize:12];
        _subjectLabel.textColor = kLightGrayColor;
    }
    return _subjectLabel;
}

- (UILabel *)coachLevelLabel
{
    if (!_coachLevelLabel) {
        _coachLevelLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.photo.right+15, self.subjectLabel.bottom, APPFRAME.size.width-130, 16)];
        _coachLevelLabel.font = [UIFont systemFontOfSize:12];
        _coachLevelLabel.textColor = kLightGrayColor;
    }
    return _coachLevelLabel;
}

- (GXLevelControl *)starLevel
{
    if (!_starLevel) {
        _starLevel = [[GXLevelControl alloc] initWithFrame:CGRectMake(10, self.photo.bottom, 50, 20)];
        _starLevel.selectedImgUrl = @"star_selected";
        _starLevel.normalImgUrl = @"star_nor";
        _starLevel.levelTotal = 5;
    }
    return _starLevel;
}

@end
